import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/procurement',
    component: Layout,
    redirect: '/procurement/gongyin',
    name: 'procurement',
    meta: {
      title: '采购管理',
      icon: 'qq'
    },
    children: [
      {
        path: 'list',
        component: () => import('@/views/procurement/list'),
        name: 'list',
        meta: {
          title: '供应商列表'
        }
      },
      {
        hidden: true,
        path: 'xinzen',
        component: () => import('@/views/procurement/xinzen'),
        name: 'xinzen',
        meta: {
          title: '新增供应商'
        },
      },
      {
        hidden: true,
        path: 'chushen',
        component: () => import('@/views/procurement/chushen'),
        name: 'chushen',
        meta: {
          title: '初审'
        }
      },
      {
        hidden: true,
        path: 'xiangqin',
        component: () => import('@/views/procurement/xiangqin'),
        name: 'xiangqin',
        meta: {
          title: '供应商资料'
        }
      },
      {
        path: 'caigou_List',
        component: () => import('@/views/procurement/caigou_List'),
        name: 'caigou_List',
        meta: {
          title: '采购单列表'
        },
      },
      {
        hidden: true,
        path: 'caigou_minxi',
        component: () => import('@/views/procurement/caigou_minxi'),
        name: 'caigou_minxi',
        meta: {
          title: '采购明细'
        },
      },
      {
        path: 'shouhuo_List',
        component: () => import('@/views/procurement/shouhuo_List'),
        name: 'shouhuo_List',
        meta: {
          title: '收货单列表'
        },
      },
      {
        hidden: true,
        path: 'shouhuo_minxi',
        component: () => import('@/views/procurement/shouhuo_minxi'),
        name: 'shouhuo_minxi',
        meta: {
          title: '收货明细'
        },
      },
    ]
  },
  {
    path: '/merchandise',
    component: Layout,
    redirect: '/merchandise/index',
    name: 'merchandise',
    meta: {
      title: '商品管理',
      icon: 'example'
    },
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/merchandise/index'),
      meta: {
        title: '商品列表',
        icon: 'example'
      }
    }, ]
  },
  {
    path: '/stockcontrol',
    component: Layout,
    redirect: '/stockcontrol/stockexpectation',
    name: 'stockcontrol',
    meta: {
      title: '库存管理',
      icon: 'inventory'
    },
    children: [{
      path: 'stockexpectation',
      name: 'stockexpectation',
      component: () => import('@/views/stockcontrol/stockexpectation'),
      meta: {
        title: '库存展望',
        icon: 'none'
      },
      children: [{
        path: 'expectationlist',
        name: 'expectationlist',
        component: () => import('@/views/stockcontrol/stockexpectation/expectationlist'),
        meta: {
          title: '库存展望',
          icon: 'none'
        }
      }, {
        path: 'Sortingorder',
        name: 'Sortingorder',
        component: () => import('@/views/stockcontrol/stockexpectation/Sortingorder'),
        meta: {
          title: '分拣单(计划)',
          icon: 'none'
        },
        hidden: true
      }, {
        path: 'packinglist',
        name: 'packinglist',
        component: () => import('@/views/stockcontrol/stockexpectation/packinglist'),
        meta: {
          title: '装箱单(计划)',
          icon: 'none'
        },
        hidden: true
      }]
    }, {
      path: 'indexlist',
      name: 'indexlist',
      component: () => import('@/views/stockcontrol/indexlist'),
      meta: {
        title: '入库列表',
        icon: 'none'
      }
    }, {
      path: 'Outboundlist',
      name: 'Outboundlist',
      component: () => import('@/views/stockcontrol/Outboundlist'),
      meta: {
        title: '出库列表',
        icon: 'none'
      }
    }, {
      path: 'Repairorder',
      name: 'Repairorder',
      component: () => import('@/views/stockcontrol/Repairorder'),
      meta: {
        title: '出入库汇总表',
        icon: 'none'
      }
    }]
  },
  {
    path: '/management',
    component: Layout,
    redirect: 'management/headList',
    name: 'management',
    meta: {
      title: '分拣加工',
      icon: 'nested'
    },
    children: [{
        path: 'menu1',
        component: () => import('@/views/management/menu1'),
        name: 'menu1',
        meta: {
          title: '分拣计划'
        }
      },
      {
        path: 'menu2',
        component: () => import('@/views/management/menu2'),
        name: 'menu2',
        meta: {
          title: '分拣单详情'
        },
        hidden: true
      },
      {
        path: 'menu3',
        component: () => import('@/views/management/menu3'),
        name: 'menu3',
        meta: {
          title: '新增分拣单'
        },
        hidden: true
      },
      {
        path: 'menu4',
        component: () => import('@/views/management/menu4'),
        name: 'menu4',
        meta: {
          title: '编辑分拣单'
        },
        hidden: true
      },
      {
        path: 'packingDetails',
        component: () => import('@/views/management/packingDetails'),
        name: 'packingDetails',
        meta: {
          title: '装箱单详情'
        },
        hidden: true
      },
      {
        path: 'sortingPlan',
        component: () => import('@/views/management/sortingPlan'),
        name: 'sortingPlan',
        meta: {
          title: '分拣主管'
        }
      },
      {
        path: 'sitePacking',
        component: () => import('@/views/management/sitePacking'),
        name: 'sitePacking',
        meta: {
          title: '装箱单-场地'
        }
      },
      {
        path: 'packingDetail',
        component: () => import('@/views/management/packingDetail'),
        name: 'packingDetail',
        meta: {
          title: '装箱单-明细'
        },
        hidden: true
      },
      {
        path: 'addsortmang',
        name: 'addsortmang',
        component: () => import('@/views/management/addsortmang'),
        meta: { title: '新增分拣管理' },
        hidden: true
      },
      {
        path: 'editsortmang',
        name: 'editsortmang',
        component: () => import('@/views/management/editsortmang'),
        meta: { title: '编辑分拣主管' },
        hidden: true
      }
    ]
  },
  {
    path: '/organizationmanage',
    component: Layout,
    redirect: '/organizationmanage/groupList',
    name: 'organizationmanage',
    meta: {
      title: '组织管理',
      icon: 'form'
    },
    children: [{
        path: 'groupList',
        component: () => import('@/views/organizationmanage/groupList'), // Parent router-view
        name: 'groupList',
        meta: {
          title: '组织列表',
          icon: 'tree'
        }
      },
      {
        path: 'membermanage',
        name: 'membermanage',
        component: () => import('@/views/organizationmanage/membermanage'),
        meta: { title: '成员管理' },
        hidden: true
      },
      {
        path: 'adduser',
        name: 'adduser',
        component: () => import('@/views/organizationmanage/adduser'),
        // meta: { title: '新增成员' },
        // hidden: true
      }
      // {
      //   path: 'organizationdetail',
      //   name: 'organizationdetail',
      //   component: () => import('@/views/organizationmanage/organizationdetail')
      //   // meta: { title: 'menu2' }
      // },
      // {
      //   path: 'editorganization',
      //   name: 'editorganization',
      //   component: () => import('@/views/organizationmanage/editorganization')
      //   // meta: { title: 'menu2' }
      // },
      // {
      //   path: 'addorganization',
      //   name: 'addorganization',
      //   component: () => import('@/views/organizationmanage/addorganization')
      //   // meta: { title: 'menu2' }
      // }
    ]
  },
  {
    path: '/financial',
    component: Layout,
    name: 'financial',
    meta: {
      title: '财务管理',
      icon: 'password'
    },
    children: [{
        path: 'accountlist',
        component: () => import('@/views/financial/accountlist'),
        name: 'accountlist',
        meta: {
          title: '供应商结算列表'
        }
      },
      {
        path: 'financialdetail',
        component: () => import('@/views/financial/financialdetail'),
        name: 'financialdetail',
      },
      {
        path: 'financialdetail-detail',
        component: () => import('@/views/financial/financialdetail-detail'),
        name: 'financialdetail-detail',
      },
    ]
  },
  {
    path: '/salesOrder',
    component: Layout,
    name: 'salesOrder',
    meta: {
      title: '销售管理',
      icon: 'distribution'
    },
    children: [{
        path: 'sendFood',
        component: () => import('@/views/salesOrder/sendFood'),
        name: 'sendFood',
        meta: {
          title: '送菜订单'
        }
      },
      {
        path: 'orderSummary',
        component: () => import('@/views/salesOrder/orderSummary'),
        name: 'orderSummary',
        meta: {
          title: '订单汇总'
        }
      }
    ]
  },
  {
    path: '/rightsManagement',
    component: Layout,
    name: 'rightsManagement',
    meta: {
      title: '权限管理',
      icon: 'user'
    },
    children: [{
        path: 'account',
        component: () => import('@/views/rightsManagement/account'),
        name: 'account',
        meta: {
          title: '账户管理'
        }
      },
      {
        path: 'role',
        component: () => import('@/views/rightsManagement/role'),
        name: 'role',
        meta: {
          title: '角色管理'
        }
      },
      {
        path: 'group',
        component: () => import('@/views/rightsManagement/group'),
        name: 'group',
        meta: {
          title: '账户分组'
        },
        hidden: true
      },
      {
        path: 'opiModel',
        component: () => import('@/views/rightsManagement/opiModel'),
        name: 'opiModel',
        meta: {
          title: '账户分组'
        },
        // hidden: true
      },
      {
        path: 'addrole',
        component: () => import('@/views/rightsManagement/addrole'),
        name: 'addrole',
        meta: {
          title: '增加角色'
        },
        hidden: true
      },
    ]
  },
  {
    path: '/deliveryRoutes',
    component: Layout,
    name: 'deliveryRoutes',
    meta: {
      title: '配送管理',
      icon: 'distribution'
    },
    children: [{
        path: 'distributionlist',
        component: () => import('@/views/deliveryRoutes/distributionlist'),
        name: 'distributionlist',
        meta: {
          title: '配送单列表'
        }
      },
      {
        path: 'distributionlist1',
        component: () => import('@/views/deliveryRoutes/distributionlist1'),
        name: 'distributionlist1',
        meta: {
          title: '配送线路'
        }
      },
      // {
      //   path: 'distributionBasket',
      //   component: () => import('@/views/deliveryRoutes/distributionBasket'),
      //   name: 'distributionBasket',
      //   meta: { title: '配送篮设置' }
      // },
      {
        path: 'marki',
        component: () => import('@/views/deliveryRoutes/marki'),
        name: 'marki',
        meta: {
          title: '配送员管理'
        }
      },
    ]
  },

  {
    path: '/partners',
    component: Layout,
    name: 'partners',
    meta: {
      title: '合作伙伴',
      icon: 'distribution'
    },
    children: [{
        path: 'supplier',
        component: () => import('@/views/partners/supplier'),
        name: 'supplier',
        meta: {
          title: '供应商'
        },
        children: [{
            path: 'supplierList',
            component: () => import('@/views/partners/supplier/supplierList'),
            name: 'supplierList',
            meta: {
              title: '我的资质'
            },
          },
          {
            path: 'myattributes',
            component: () => import('@/views/partners/supplier/myattributes'),
            name: 'myattributes',
          },
          {
            path: 'shoppinglist',
            component: () => import('@/views/partners/supplier/shoppinglist'),
            name: 'shoppinglist',
            meta: {
              title: '采购单列表'
            },
          },
          {
            path: 'shoppingdetail',
            component: () => import('@/views/partners/supplier/shoppingdetail'),
            name: 'shoppingdetail',
          },
          {
            path: 'deliverylist',
            component: () => import('@/views/partners/supplier/deliverylist'),
            name: 'deliverylist',
            meta: {
              title: '送货单列表'
            },
          },
          {
            path: 'deliverydetail',
            component: () => import('@/views/partners/supplier/deliverydetail'),
            name: 'deliverydetail',
          },
          {
            path: 'statementlist',
            component: () => import('@/views/partners/supplier/statementlist'),
            name: 'statementlist',
            meta: {
              title: '结算单列表'
            },
          },
          {
            path: 'statementdetail',
            component: () => import('@/views/partners/supplier/statementdetail'),
            name: 'statementdetail',
          },
          {
            path: 'statementde-detail',
            component: () => import('@/views/partners/supplier/statementde-detail'),
            name: 'statementde-detail',
          },
        ]
      },
      // {
      //   path:'supplierList',
      //   component: () => import('@/views/partners/supplierList'),
      //   name:'supplierList',
      //   meta: { title: '供应商列表' },
      // }
      {
        path: 'propertyManagement',
        component: () => import('@/views/partners/propertyManagement'),
        name: 'propertyManagement',
        meta: {
          title: '物业管理公司'
        },
        children: [{
          path: 'BuildingnoList',
          component: () => import('@/views/partners/propertyManagement/BuildingnoList'),
          name: 'BuildingnoList',
          meta: {
            title: '楼房号列表',
          }
        }, {
          path: 'propertyfeeList',
          component: () => import('@/views/partners/propertyManagement/propertyfeeList'),
          name: 'propertyfeeList',
          meta: {
            title: '审核物业管理费列表',
          }
        }, {
          path: 'propertyfeedetails',
          component: () => import('@/views/partners/propertyManagement/propertyfeedetails'),
          name: 'propertyfeedetails',
          meta: {
            title: '审核物业管理费详情',
          },
          hidden: true
        }, {
          path: 'StatementsList',
          component: () => import('@/views/partners/propertyManagement/StatementsList'),
          name: 'StatementsList',
          meta: {
            title: '结算单列表'
          }
        }, {
          path: 'Statementsdetails',
          component: () => import('@/views/partners/propertyManagement/Statementsdetails'),
          name: 'Statementsdetails',
          meta: {
            title: '结算单明细'
          },
          hidden: true
        }]
      },
    ]
  },
  {
    path: '/PropertyManagement',
    component: Layout,
    name: 'PropertyManagement',
    meta: {
      title: '物业管理费',
      icon: 'distribution'
    },
    children: [{
      path: 'bindingBuildingnoList',
      component: () => import('@/views/PropertyManagement/bindingBuildingnoList'),
      name: 'bindingBuildingnoList',
      meta: {
        title: '绑定楼房号列表'
      }
    }, {
      path: 'confirmPropertyManagementList',
      component: () => import('@/views/PropertyManagement/confirmPropertyManagementList'),
      name: 'confirmPropertyManagementList',
      meta: {
        title: '审核物业管理费'
      }
    }, {
      path: 'Stratafeedetails',
      component: () => import('@/views/PropertyManagement/Stratafeedetails'),
      name: 'Stratafeedetails',
      meta: {
        title: '物业管理费明细'
      },
      hidden: true
    }, {
      path: 'PropertyStatementsList',
      component: () => import('@/views/PropertyManagement/PropertyStatementsList'),
      name: 'PropertyStatementsList',
      meta: {
        title: '结算单列表(运营)'
      }
    }, {
      path: 'PropertyStatementsdetails',
      component: () => import('@/views/PropertyManagement/PropertyStatementsdetails'),
      name: 'PropertyStatementsdetails',
      meta: {
        title: '结算单明细'
      },
      hidden: true
    }, {
      path: 'neighborTransferList',
      component: () => import('@/views/PropertyManagement/neighborTransferList'),
      name: 'neighborTransferList',
      meta: {
        title: '邻居点转账列表'
      }
    }, {
      path: 'PropertycompanyList',
      component: () => import('@/views/PropertyManagement/PropertycompanyList'),
      name: 'PropertycompanyList',
      meta: {
        title: '物业管理公司列表'
      }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
